package com.hz.cheetahclient.config;

import com.hz.cheetah.client.CheetahByJDKProxy;
import com.hz.cheetah.hub.zookeeper.ZooKeeperServiceDiscovery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * Created by yangchuan on 17/2/16.
 */
@Configuration
@EnableConfigurationProperties({ClientConfig.class})
@Import(ClientConfigRegistrar.class)
public class ClientAutoConfig {

    @Autowired
    private ClientConfig myConfig;

    @Autowired
    @Bean(name = "cheetahByJDKProxy")
    @ConditionalOnMissingBean
    public CheetahByJDKProxy cheetahServer(ZooKeeperServiceDiscovery serviceDiscovery) {
        return new CheetahByJDKProxy(serviceDiscovery);
    }


    @Bean
    @ConditionalOnMissingBean
    public ZooKeeperServiceDiscovery zooKeeperServiceDiscovery() {
        ZooKeeperServiceDiscovery result = new ZooKeeperServiceDiscovery();
        result.setZkAddress(myConfig.getAddress());
        result.init();
        return result;
    }



}
